/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.evosoft.vista.frame;

import com.evosoft.model.Empresa;
import com.evosoft.model.Persona;
import com.evosoft.util.Sesion;
import com.evosoft.vista.Login;
import com.evosoft.vista.panel.empresa.ListaEmpresa;
import com.evosoft.vista.panel.rol.ListaRoles;
import com.evosoft.vista.panel.usuarios.ListaUsuarios;
import static javax.swing.JFrame.setDefaultLookAndFeelDecorated;
import javax.swing.JTabbedPane;
import org.pushingpixels.substance.api.SubstanceLookAndFeel;

/**
 *
 * @author Silex RPR
 */
public class MainWindow extends java.awt.Frame {

    /**
     * Creates new form MainWindow
     */
    
   
    
    public MainWindow() {
        initComponents();
        jButton1.setText("Salir");
        appTabPanel = new JTabbedPane();
        Persona personaEnSesion = Sesion.getInstance().getPersonaEnSesion();
        Empresa empresa = personaEnSesion.getEmpresa();
        if(empresa.getTipo() != null ) {
          switch(empresa.getTipo().getId()) {
            //Caso distribuidor;
            case 1: appTabPanel.addTab("Subdistribuidores", new ListaEmpresa());
            break;    
            case 2: appTabPanel.addTab("Canales", new ListaEmpresa());
            break;    
            case 3: appTabPanel.addTab("Ptos. Venta", new ListaEmpresa());
            break;    
          }
        }
        else {
           appTabPanel.addTab("Distribuidores", new ListaEmpresa());
        }
        appTabPanel.addTab("Usuarios", new ListaUsuarios());
        if(personaEnSesion.getEmpresa().getTipo() != null)
            appTabPanel.addTab("Roles", new ListaRoles());
        jPanel1.add(appTabPanel);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();

        setResizable(false);
        setTitle("Linker");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                exitForm(evt);
            }
        });

        jButton1.setText("jButton1");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 776, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addGap(23, 23, 23))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 445, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    public JTabbedPane getAppTabPanel() {
        return appTabPanel;
    }

    public void setAppTabPanel(JTabbedPane appTabPanel) {
        this.appTabPanel = appTabPanel;
    }
    
    /**
     * Exit the Application
     */
    private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
        System.exit(0);
    }//GEN-LAST:event_exitForm

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        Sesion.getInstance().setPersonaEnSesion(null);
        appTabPanel.removeAll();
        this.dispose();
        Login login = new Login();
        login.setVisible(true);
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        setDefaultLookAndFeelDecorated(true);
        SubstanceLookAndFeel.setSkin("org.pushingpixels.substance.api.skin.OfficeSilver2007Skin");
        
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                SubstanceLookAndFeel.setSkin("org.pushingpixels.substance.api.skin.OfficeSilver2007Skin");
                new MainWindow().setVisible(true);
            }
        });
    }
    
    private javax.swing.JTabbedPane appTabPanel;
    
//    
//    ChangeListener changeListener = new ChangeListener() {
//      public void stateChanged(ChangeEvent changeEvent) {
//        JTabbedPane sourceTabbedPane = (JTabbedPane) changeEvent.getSource();
//        int index = sourceTabbedPane.getSelectedIndex();
//        System.out.println("Tab changed to: " + sourceTabbedPane.getTitleAt(index));
//      }
//    };
//    appTabPanel.addChangeListener(changeListener);
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables
}
